<template>
  <div id="grade">  
   
   <div  style="display:flex;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">等级管理</div>
     </div>

   <el-form ref="form"  label-width="0px">  
    <el-row>
 
        <el-col :span="24" style="text-align: right;">  
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="add_but">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />增加
            </el-button> 
              <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="mtk1_but">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />奖励天数
            </el-button>   
        </el-col>
   

  </el-row>
  </el-form >
  
   <!-- 渲染数据list -->
   <grade-list :datalist="datalist" @up_list_fun="list_fun"> </grade-list>
  

      <!-- 添加 -->
    <el-dialog title="增加" :visible.sync="add_mtk"  width="600px">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="120px" style="width:100%;">

               <el-row>
                     <el-col :span="12">
                          <el-form-item label="标题">
                             <el-input v-model="mtk_form.title" placeholder="标题" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                        <el-form-item label="类别奖励">
                          <el-input v-model="mtk_form.reward_scale" placeholder="类别奖励" ></el-input>
                        </el-form-item>                                  
                      </el-col>
                 </el-row>

                 <!-- <el-row>
                     <el-col :span="12">
                          <el-form-item label="奖励天数">
                             <el-input v-model="mtk_form.reward_day" placeholder="奖励天数" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                        <el-form-item label="分享奖励天数">
                          <el-input v-model="mtk_form.extra_person_day_number" placeholder="分享奖励天数" ></el-input>
                        </el-form-item>                                  
                      </el-col>
                 </el-row> -->

                 <el-row>
                     <el-col :span="12">
                          <el-form-item label="团队人数">
                             <el-input v-model="mtk_form.need_person_number" placeholder="团队人数" ></el-input>
                         </el-form-item>       
                     </el-col>
                     <el-col :span="12">
                       <el-form-item label="团队标的等级">
                            <el-select  v-model="mtk_form.need_person_grade_id"   placeholder="团队标的等级" style="width:100%;">
                                <el-option  v-for="(item,index) in type_data" :key="index" :label="item.title" :value="item.grade_id"></el-option>
                            </el-select>
                     </el-form-item>  
                      </el-col>
                 </el-row>

                  <el-row>
                     <el-col :span="12">
                          <el-form-item label="好友人数">
                             <el-input v-model="mtk_form.need_direct_person_number" placeholder="好友人数" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                         <el-form-item label="好友标的等级">
                                <el-select  v-model="mtk_form.need_direct_person_grade_id"   placeholder="好友标的等级" style="width:100%;">
                                    <el-option  v-for="(item,index) in type_data" :key="index" :label="item.title" :value="item.grade_id"></el-option>
                                </el-select>
                          </el-form-item>                                   
                      </el-col>
                 </el-row>


                  <el-row>
                     <el-col :span="12">
                          <el-form-item label="经验值">
                             <el-input v-model="mtk_form.need_experience" placeholder="经验值" ></el-input>
                         </el-form-item>       
                     </el-col>
                      <el-col :span="12">
                         <!-- <el-form-item label="是否开启">
                                <el-select  v-model="mtk_form.select_num"   placeholder="是否开启" style="width:100%;">
                                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                                </el-select>
                          </el-form-item>   -->
                      </el-col>
                 </el-row>

                 <el-row style="width:100%;">
                     <el-col :span="12">
                        <el-form-item label="等级图标">
                            <el-upload 
                                  action="uploadUrl"  
                                  :show-file-list="false"   
                                  :before-upload="beforeupload"
                                  :http-request="ImgUploadSectionFile">
                                  <div class="avatar-uploader">
                                      <img v-if="pic_form.head_img"  :src="pic_form.head_img" class="avatar">
                                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                  </div>
                            </el-upload>
                         </el-form-item>       
                     </el-col> 

                </el-row>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="add_but_qr">确认</el-button>
            </div>
         </el-form>
        </div> 
    </el-dialog>


   <!-- 奖励天数 -->
    <el-dialog title="奖励天数" :visible.sync="mtk1"  width="600px">
        <div style="width:100%;"> 

          <el-col :span="24">  
                  <div style="height:50px;background: #4F81BC;display:flex;line-height:50px;margin-bottom:15px;">
                      <div style="width:80px;;color:white;padding-left:10px;border-right:1px solid white;">名称</div>
                      <div style="flex:1;color:white;padding-left:10px;border-right:1px solid white;">奖励天数</div>
                      <div style="flex:1;color:white;padding-left:10px;">分享奖励天数</div>
                  </div>
          </el-col> 

           <el-form ref="form"   label-width="100px" style="width:100%;">
                   
                <el-form-item  v-for="(item,index) in mtk1_form.datalist" :key="index" :label="item.title">
                    <el-col :span="11">
                      <el-input v-model.number="item.reward_days" placeholder="奖励天数" ></el-input>
                    </el-col>
                    <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                    <el-col :span="11">
                        <el-input v-model.number="item.reward_days_share" placeholder="分享奖励天数" ></el-input>
                    </el-col>
                </el-form-item>  

           </el-form>

           <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="mtk1_qr_but">确认</el-button>
            </div>

        </div> 
    </el-dialog>
      
  </div>
</template>

<script>
import GradeList from '@/view/Jindou/GradeLits'
export default {
  name: 'grade',
  data () {
    return {
        datalist:[],
        add_mtk:false,
        mtk_form:{
           title:'',
            reward_scale:'',
            reward_day:'',
            extra_person_day_number:'',
            need_person_number:'',
            need_person_grade_id:'',
            need_direct_person_number:'',
            need_direct_person_grade_id:'',
            need_experience:'',
            select_num:0,
        },
        select_data:[{"id":1,"name":"关闭"},{"id":0,"name":"开启"}],
        type_data:[],
        pic_form:{
           head_img:'',
           upfile:'',
        },
        mtk1:false,
        mtk1_form:{
            datalist:[]
        }
    }
  },
 components:{
    GradeList
  },
  created(){
      this.type_fun()
     this.list_fun()
  },
  mounted (){
    
  },
  methods: {
      type_fun(){
          
           this.post("/user_grade/optionOfGrade", {

	        }).then(res => {
            //this.datalist = res.result
            this.type_data = res.result
            //console.log(res)
         })
      },
      list_fun(){
          this.post("/user_grade/listOfData", {

	        }).then(res => {
            this.datalist = res.result
            console.log(res,"dddd")
         })
      },
      mtk1_but(){
          this.mtk1_fun()
          this.mtk1 = true
      },
      mtk1_fun(){
           this.post("/user_grade/listOfRewardDays", {

	        }).then(res => {
             this.mtk1_form.datalist = res.result
             //console.log(this.mtk1_form.datalist,"dddd")
         })
      },
      mtk1_qr_but(){

        this.post("/user_grade/updateRewardDays", {
              arr:this.mtk1_form.datalist
          }).then(res => {

              if(res.error_code == 0){
              this.open1(res.result,'success')  //提示框
              this.mtk1_fun()
              this.mtk1 = false
              }else {
              this.open1(res.message,'warning')
          }

        })
        
      },
      add_but(){
          this.add_mtk = true
          this.mtk_form={
            title:'',
            reward_scale:'',
            reward_day:'',
            extra_person_day_number:'',
            need_person_number:'',
            need_person_grade_id:'',
            need_direct_person_number:'',
            need_direct_person_grade_id:'',
            need_experience:'',
            select_num:'',
         }
      },
     add_but_qr(){
          this.post("/user_grade/create", {
              title:this.mtk_form.title,
              reward_scale:this.mtk_form.reward_scale,
              reward_day:this.mtk_form.reward_day,
              extra_person_day_number:this.mtk_form.extra_person_day_number,
              need_person_number:this.mtk_form.need_person_number,
              need_person_grade_id:this.mtk_form.need_person_grade_id,
              need_direct_person_number:this.mtk_form.need_direct_person_number,
              need_direct_person_grade_id:this.mtk_form.need_direct_person_grade_id,
              need_experience:this.mtk_form.need_experience,
              hide:this.mtk_form.select_num,
              logo:this.pic_form.upfile,
          }).then(res => {

              if(res.error_code == 0){
              this.open1(res.result,'success')  //提示框
              this.list_fun()
              this.add_mtk = false
              }else {
              this.open1(res.message,'warning')
          }

        })
     },
     beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form.head_img=windowURL.createObjectURL(file);             
            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
              console.log(res.result.url )
               this.pic_form.upfile = res.result.url    
            })

            return false;
     },
      ImgUploadSectionFile(param){//图片上传    
      },

  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>
